<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>regist</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link rel="stylesheet" type="text/css" href="css/style.css" />
		<link rel="stylesheet" href="css/bootstrap.min.css">
		<!-- 可选的Bootstrap主题文件（一般不用引入） -->
		<link rel="stylesheet" href="css/bootstrap-datepicker.min.css">
		<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
		<script src="js/jquery.js"></script>
		<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
		<script src="js/bootstrap.min.js"></script></span>
	</head>
	<body onLoad="startTime()">
		<div id="wrap">
			<div id="top_content">
					<div id="header">
						<div id="rightheader">
							<p id="time">

								<br />
							</p>
						</div>
						<div id="topheader">
							<h1 id="title">
								<a href="#">华夏医院在线平台</a>
							</h1>
						</div>
						<div id="navigation">
						</div>
					</div>
				<div id="content">
					<p id="whereami">
					</p>
					<h1 style="margin-left: 330px">
						医生注册
					</h1>
					<form action="photos/login.html" method="post">
						<table cellpadding="0" cellspacing="0" border="0"
							class="form_table" style="margin-left:190px">
							<tr>
								<td valign="middle" align="right">
									姓名:
								</td>
								<td valign="middle" align="left">
									<input type="text" class="inputgri" class="form-control" placeholder="姓名" aria-describedby="basic-addon1" v-model="doctor.name" />
								</td>
							</tr>
							<tr>
								<td valign="middle" align="right">
									联系方式:
								</td>
								<td valign="middle" align="left">
									<input type="text" class="inputgri" class="form-control" placeholder="联系方式" aria-describedby="basic-addon1" v-model="doctor.tel"/>
								</td>
							</tr>
							<tr>
								<td valign="middle" align="right">
									密码:
								</td>
								<td valign="middle" align="left">
									<input type="password" class="inputgri"placeholder="密码" v-model="doctor.password" />
								</td>
							</tr>
							<tr>
								<td valign="middle" align="right">
									证件号码:
								</td>
								<td valign="middle" align="left">
									<input type="text" class="inputgri" placeholder="证件号码" v-model="doctor.id_card" id="idCard"@blur="age(doctor.id_card)" />
								</td>
							</tr>
							<tr>
								<td valign="middle" align="right">
									性别:
								</td>
								<td valign="middle" align="left">
									男
									<input type="radio" class="inputgri" v-model="doctor.sex" value='男' checked name="sex" id="man"/>
									女
									<input type="radio" class="inputgri" v-model="doctor.sex" value='女' name="sex" id="woman" checked="false"/>
								</td>
							</tr>

							<tr>
								<td valign="middle" align="right">
									年龄:
								</td>
								<td valign="middle" align="left">
									<input type="text" class="inputgri"placeholder="年龄" v-model="doctor.age" id="age"ref="mybox"  />
								</td>
							</tr>

							<tr>
								<td valign="middle" align="right">
									院区名称:
								</td>
								<td valign="middle" align="left">
									<!--									<input type="text" class="inputgri"placeholder="department" v-model="doctor.department" />-->
									<select  v-model="doctor.area">
										<option value=1>汉口区分院</option>
										<option value=2>武昌区分院 </option>
										<option value=3>江汉区分院</option>
									</select>
								</td>
							</tr>
							<tr>
								<td valign="middle" align="right">
									部门名称:
								</td>
								<td valign="middle" align="left">
<!--									<input type="text" class="inputgri"placeholder="department" v-model="doctor.department" />-->
									<select  v-model="doctor.department">
										<option value="内科">内科</option>
										<option value="脑外科">脑外科 </option>
										<option value="肿瘤">肿瘤</option>
										<option value="耳鼻咽喉科">耳鼻咽喉科</option>
										<option value="骨科">骨科</option>
										<option value="妇产科">妇产科</option>
										<option value="皮肤科">皮肤科</option>
										<option value="神经内科">神经内科</option>
										<option value="整形外科">整形外科</option>
										<option value="精神病">精神病</option>
										<option value="口腔科">口腔科</option>
										<option value="儿科">儿科</option>
										<option value="泌尿科">泌尿科</option>
										<option value="外科">外科</option>
										<option value="传染病">传染病</option>
										<option value="眼科">眼科</option>
										<option value="妇科">妇科</option>
										<option value="男科">男科</option>
										<option value="烧伤科">烧伤科</option>
									</select>
								</td>
							</tr>




							<img id="num" :src="url" style="position:absolute;left:890px;top: 520px;height:40px"/>
							<tr>
								<td valign="middle" align="right">
									验证码:
									<a href="javascript:;" @click="getImg">换一张</a>

								</td>
								<td valign="middle" align="left">
									<input type="text" class="inputgri" v-model="code" />
								</td>
							</tr>
						</table>
						<p>
							<input type="button" @click="register" class="btn btn-default" value="注册 "style="margin-left:350px;width:55px" id="btn"disabled="disabled" />
						</p>
					</form>
				</div>
			</div>
			<div id="footer">
				<div id="footer_bg">
					Copyright © 小凡哥 All rights reserved.
					li123fan00@foxmail.com
				</div>
			</div>
		</div>
	</body>
</html>
<script src="/es_healthy/js/vue.js"></script>
<script src="/es_healthy/js/axios.min.js"></script>

<script>
	function startTime()
	{
		var today=new Date();//定义日期对象
		var yyyy = today.getFullYear();//通过日期对象的getFullYear()方法返回年
		var MM = today.getMonth()+1;//通过日期对象的getMonth()方法返回年
		var dd = today.getDate();//通过日期对象的getDate()方法返回年
		var hh=today.getHours();//通过日期对象的getHours方法返回小时
		var mm=today.getMinutes();//通过日期对象的getMinutes方法返回分钟
		var ss=today.getSeconds();//通过日期对象的getSeconds方法返回秒
		// 如果分钟或小时的值小于10，则在其值前加0，比如如果时间是下午3点20分9秒的话，则显示15：20：09
		MM=checkTime(MM);
		dd=checkTime(dd);
		mm=checkTime(mm);
		ss=checkTime(ss);
		var day; //用于保存星期（getDay()方法得到星期编号）
		if(today.getDay()==0)   day   =   "星期日 "
		if(today.getDay()==1)   day   =   "星期一 "
		if(today.getDay()==2)   day   =   "星期二 "
		if(today.getDay()==3)   day   =   "星期三 "
		if(today.getDay()==4)   day   =   "星期四 "
		if(today.getDay()==5)   day   =   "星期五 "
		if(today.getDay()==6)   day   =   "星期六 "
		document.getElementById('time').innerHTML=yyyy+"-"+MM +"-"+ dd +" " + hh+":"+mm+":"+ss+"   " + day;
		setTimeout('startTime()',1000);//每一秒中重新加载startTime()方法
	}

	function checkTime(i)
	{
		if (i<10){
			i="0" + i;
		}
		return i;
	}

</script>
<script>
	$(function(){
		$('#idCard').blur(function(){
			let orginnumber =$('#idCard').val();
			// alert(orginnumber);
			let partn = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;//先用正则判断是否为正确的格式
			if (!partn.exec(orginnumber))
			{
				alert('请检查你输入的身份证个式是否正确！');
			}else{
				let number = [...orginnumber]; //es6语法，利用...将变量的值转成数组。
				let ration= new Array("7","9","10","5","8","4","2","1","6","3","7","9","10","5","8","4","2");//系数
				let ration22= new Array("1","0","X","9","8","7","6","5","4","3","2");
				let sum=0;
				console.log(ration);
				for(let i=0;i<number.length-1;i++){
					sum=number[i]*ration[i]+sum;
					// console.log(i);
				}
				let mod = sum%11;
				if(ration22[mod]==number[17]){
					document.getElementById("btn").removeAttribute("disabled");
					//获取性别
					if (parseInt(orginnumber.substr(16, 1)) % 2 == 1) {
						//男
						// alert("nan");
						// $("#woman").removeAttr("checked");
						$("#man").click();

					} else {
						//女
						// alert("nv");
						// $("#man").removeAttr("checked");
						$("#woman").click();

					}

				}else{
					alert('不正确,无法提交数据');
					document.getElementById("btn").disabled = "disabled";
				}
			}
		})

	})



</script>
<script>
	var app=new Vue({
		el:"#wrap",
		data:{
			url:"",
			doctor:{
				sex:"男"
			},
			code:"",

		},
		methods:{
			age(orginnumber){
				var myDate = new Date();
				var month = myDate.getMonth() + 1;
				var day = myDate.getDate();
				var age = myDate.getFullYear() - orginnumber.substring(6, 10) - 1;
				if (orginnumber.substring(10, 12) < month || orginnumber.substring(10, 12) == month && orginnumber.substring(12, 14) <= day) {
					age++;
				}
				console.log(age);
				this.doctor.age=age;
				this.$refs.mybox.placeholder =age;
			},
			getImg(){
				this.getSrc();
			},
			//获取验证码
			getSrc(){
				var _this = this;
				axios.get("http://localhost:8080/es_healthy/user/getImage?time="+Math.random()).then(res=>{
					console.log(res.data);
					_this.url = res.data;
				})
			},
			//手机号验证
			isPhone(phone){
				const reg = /^[1][3,4,5,7,8][0-9]{9}$/;
				if (phone == '' || phone == undefined || phone == null) {

				} else {
					if ((!reg.test(phone)) && phone != '') {
						new Error('请输入正确的电话号码');
						return false;
					}
					return true;
				}
			},
			//注册用户信息
			register() {
				if(this.isPhone(this.doctor.tel)){
					var role=sessionStorage.getItem("role");
					if(role=="admin"){
						axios.post("http://localhost:8080/es_healthy/doctor/register?code="+this.code+"&token="+sessionStorage.getItem("token"),this.doctor).then(res=>{
							if(res.data.state)
							{
								alert(res.data.msg+",点击确定跳转至登陆页面");
								window.history.go(-1);
							}else
							{
								alert(res.data.msg);
							}

						});

					}else{
						alert(res.data.msg);
						location.href="/es_healthy/loginAdmin.html";
					}
				}else
				{
					alert("请输入正确的手机号");
				}

			}


		},
		created(){
			this.getSrc();
		}
	})
</script>